﻿/*
 * admin area的dept控制器
 * */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WH.NurseSys.BLL;
using WH.NurseSys.Model;

namespace WH.NurseSys.Web.Areas.Admin.Controllers
{
    public class DeptController : Controller
    {
        //列表
        public ActionResult List()
        {
            DeptBLL deptBLL = new DeptBLL();
            List<Dept> deptList = deptBLL.GetList();
            return View(deptList);
        }

        //插入一个新的dept
        [HttpPost]
        public ActionResult Insert(string id)
        {
            string name = Request.Form["name"];
            if (!string.IsNullOrWhiteSpace(name))
            {                
                DeptBLL deptBLL = new DeptBLL();
                if (!deptBLL.Exist(name))
                {
                    Dept dept = new Dept();
                    dept.Id = Guid.NewGuid();
                    dept.Name = name;
                    deptBLL.Insert(dept);
                }
            }
            return Redirect("/admin/dept/list/");
        }

        //更新dept展示页
        [HttpGet]
        public ActionResult Update()
        {
            return View();
        }

        //更新dept
        [HttpPost]
        public ActionResult Update(string id)
        {
            throw new NotImplementedException();
        }

        //删除dept
        public ActionResult Delete(Guid id)
        {
            new DeptBLL().Delete(id);
            return Redirect("/admin/dept/list");
        }
    }
}
